import { observable, action } from 'mobx';
import { toJS } from 'mobx';
import { RouteLayout } from 'weaver-mobile-page';

import RelateStore from './RelateStore';
import CollectStore from './CollectStore';
import MonitorStore from './MonitorStore';
import ContentMonitorStore from './ContentMonitorStore';
import CommentMonitorStore from './CommentMonitorStore';
import PublishStore from './PublishStore';

import * as Api from '../../api/CenterApi';

export default class CenterStore {

  @observable relateStore = new RelateStore();
  @observable monitorStore = new MonitorStore();
  @observable collectStore = new CollectStore();
  @observable contentMonitorStore = new ContentMonitorStore();
  @observable commentMonitorStore = new CommentMonitorStore();
  @observable publishStore = new PublishStore();
  
  @observable joinLayout = new RouteLayout.Store({ route: '/center', id: 'join' }); // 参与的协作
  @observable responseLayout = new RouteLayout.Store({ route: '/center', id: 'response' }); // 负责的协作
  @observable createCoworkListLayout = new RouteLayout.Store({ route: '/center', id: 'createCoworkList' }); // 创建的协作
  @observable relateLayout = new RouteLayout.Store({ route: '/center', id: 'relate' }); // 与我相关
  @observable publishLayout = new RouteLayout.Store({ route: '/center', id: 'publish' }); // 我的发表
  @observable collectLayout = new RouteLayout.Store({ route: '/center', id: 'collect' }); // 收藏的帖子
  @observable themeLayout = new RouteLayout.Store({ route: '/center', id: 'theme' }); // 主题监控
  @observable contentLayout = new RouteLayout.Store({ route: '/center', id: 'content' }); // 内容监控
  @observable commentsLayout = new RouteLayout.Store({ route: '/center', id: 'comment' }); // 评论监控

  @observable pathMap = [
    { key: 'join', name: '参与的协作', path: '/center/join' },
    { key: 'response', name: '负责的协作', path: '/center/response' },
    { key: 'createCoworkList', name: '创建的协作', path: '/center/createCoworkList' },
    { key: 'relate', name: '与我相关', path: '/center/relate' },
    { key: 'publish', name: '我的发表', path: '/center/publish' },
    { key: 'collect', name: '收藏的帖子', path: '/center/collect' },
    { key: 'theme', name: '主题监控', path: '/center/theme' },
    { key: 'content', name: '内容监控', path: '/center/content' },
    { key: 'comment', name: '评论监控', path: '/center/comment' },
  ]
  @observable coworkCounts={};
  @observable userInfo={};

  @action setStoreState = (params) => {
    Object.keys(params).forEach(key => {
      this[key] = params[key];
    })
  }

  @action getPath = (key) => toJS(this.pathMap).filter(v => v.key === key)[0].path;

  @action('协作数量')
  getCoworkCounts = () => {
    Api.getCoworkCounts().then(res => {
      this.coworkCounts = res;
    })
  }

  @action('人员头像信息')
  getUserInfo = () => {
    Api.getUserInfo().then(res => {
      this.userInfo = res.user;
    })
  }
}